package com.example.demo1.Service;

import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultRequest;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultResponse;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CaptchaService {
    @Value("${captcha.SecretId}")
    private  String secretId;
    @Value("${captcha.SecretKey}")
    private  String secretKey;

    public boolean VerifyTicket(String ticket, String randStr){

        try{


            Credential cred = new Credential(secretId,secretKey);

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("captcha.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);

            DescribeCaptchaResultRequest req = new DescribeCaptchaResultRequest();
            req.setTicket(ticket);
            req.setRandstr(randStr);
            req.setCaptchaType(9L);
            req.setUserIp("");
            req.setCaptchaAppId(205165243L);
            req.setAppSecretKey("");
            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);
            System.out.println("1");
            System.out.println(DescribeCaptchaResultResponse.toJsonString(resp));
            System.out.println(resp);
            //https://cloud.tencent.com/document/product/1110/36839
            //步骤3:服务器接入的 核查验证码票据 中的代码生成，对应填上自己的数据
        } catch (TencentCloudSDKException e) {
            System.out.println(e);
            return false;
        }
        return true;
    }
}
